package client.comm.baoding.ui.vm

import android.app.Application
import android.net.Uri
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import client.comm.baoding.api.bean.TxJl
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.commlib.utils.StoreUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response

class PersonInfoViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)
    val userAvatar = MutableLiveData<Uri>()
    val callUser = MutableLiveData<JsonResult<UserInfo>>()
    val callEditName = MutableLiveData<JsonResult<Ret>>()

    val pageOne = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<TxJl>>()

    fun userInfo() {
        hold({
            server.userinfo().apply {
                body()?.let {
                    if (it.isSuccess) {
                        StoreUtil.saveBean(getApplication(), it.data!!)
                    }
                }
            }
        }, success = {
            callUser.value = it
        })
    }


}